cd ""
use "coef_wide.dta", clear

** Table 1

* HL
meologit HL_7 global i.issue influence us distance_HL ln_n pre_diff_HL if p_HL_10==1 || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)')  lab replace
*US
meologit HL_7 global i.issue i.party influence  distance_HL ln_n  pre_diff_HL if us==1 & p_HL_10==1 || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)')  lab append
* HM
meologit HM_7 global i.issue influence us distance_HM ln_n  pre_diff_HM if p_HM_10==1 || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)')  lab append
*US
meologit HM_7 global i.issue i.party influence distance_HM ln_n  pre_diff_HM if us==1 & p_HM_10==1 || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)')  lab append
* ambiguous cases
melogit rescale_p_HL_10 global i.issue i.party influence distance_HL  us  ln_n  pre_diff_HL || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)')  lab append

melogit rescale_p_HM_10 global i.issue i.party influence distance_HM  us  ln_n  pre_diff_HM || study:
outreg2 using reg_table, tex  dec(2) alpha(0.05) symbol(*) addstat(Log Likelihood, `e(ll)')  lab append



**** Calculating predicted probabilities for figures 5-9: high vs low comparison
use "coef_wide.dta", clear

meologit HL_7 global i.issue influence us distance_HL ln_n pre_diff_HL if p_HL_10==1 || study:
predict pr* if e(sample)
keep if e(sample)

* General political ideology
preserve
keep pr1-pr7 global
foreach v of varlist pr1-pr7 {
bysort global: egen re_`v'=mean(`v')
}

label define yesno_gl  0 "No" 1 "Yes"
label values global yesno_gl

keep global re_*
duplicates drop re_pr1, force
reshape long re_pr, i(global) j(HL_7)

ren global lab
decode lab, g(re_lab)
g byvar="General political ideology"

save "prpHL_global.dta", replace
restore

* Policy domain:
preserve
keep pr1-pr7 issue
foreach v of varlist pr1-pr7 {
bysort issue: egen re_`v'=mean(`v')
}

keep issue re_*
duplicates drop re_pr1, force
reshape long re_pr, i(issue) j(HL_7)

ren issue lab
decode lab, g(re_lab)
g byvar="Issue"

save "prpHL_issue.dta", replace
restore

* N of groups included in model
preserve
keep pr1-pr7 influence
foreach v of varlist pr1-pr7 {
bysort influence: egen re_`v'=mean(`v')
}

keep influence re_*
duplicates drop re_pr1, force
reshape long re_pr, i(influence) j(HL_7)

ren influence lab
decode lab, g(re_lab)
g byvar="N of groups included in a model"

save "prpHL_influence.dta", replace
restore

* Region
preserve
g byte temp =us
drop us
ren temp us
label define lb_us  0 "Not U.S." 1 "U.S."
label values us lb_us

keep pr1-pr7 us
foreach v of varlist pr1-pr7 {
bysort us: egen re_`v'=mean(`v')
}

keep us re_*
duplicates drop re_pr1, force
reshape long re_pr, i(us) j(HL_7)

ren us lab
decode lab, g(re_lab)
g byvar="Region"

save "prpHL_region.dta", replace
restore

* Partisanship
use "coef_wide.dta", clear

meologit HL_7 global i.issue i.party influence distance_HL ln_n pre_diff_HL if us==1 & p_HL_10==1 || study:
predict pr* if e(sample)
keep if e(sample)

keep pr1-pr7 party
foreach v of varlist pr1-pr7 {
bysort party: egen re_`v'=mean(`v')
}

keep party re_*
duplicates drop re_pr1, force
reshape long re_pr, i(party) j(HL_7)

ren party lab
decode lab, g(re_lab)
g byvar="Partisanship"

save "prpHL_party.dta", replace


*** combining all estimates in one dataset
use "prpHL_global.dta", clear
append using "prpHL_issue.dta"
append using "prpHL_influence.dta"
append using "prpHL_region.dta"
append using "prpHL_party.dta"

g id=1 if byvar=="Region"
replace id=2 if byvar=="N of groups included in a model"
replace id=3 if byvar=="Partisanship"
replace id=4 if byvar=="General political ideology"
replace id=5 if byvar=="Issue"

label values lab .

save "prpHL_all.dta", replace


**** Calculating predicted probabilities for figures 5-9: high vs middle comparison
use "coef_wide.dta", clear

meologit HM_7 global i.issue influence us distance_HM ln_n pre_diff_HM if p_HM_10==1 || study:
predict HMpr* if e(sample)
keep if e(sample)

* General political ideology
preserve
keep HMpr1-HMpr7 global
foreach v of varlist HMpr1-HMpr7 {
bysort global: egen re_`v'=mean(`v')
}

label define yesno_gl  0 "No" 1 "Yes"
label values global yesno_gl

keep global re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(global) j(HM_7)
ren global lab
decode lab, g(re_lab)
g byvar="General political ideology"

save "prpHM_global.dta", replace
restore

* Policy domain
preserve
keep HMpr1-HMpr7 issue
foreach v of varlist HMpr1-HMpr7 {
bysort issue: egen re_`v'=mean(`v')
}

keep issue re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(issue) j(HM_7)

ren issue lab
decode lab, g(re_lab)
g byvar="Issue"

save "prpHM_issue.dta", replace
restore

* N of groups included in model
preserve
keep HMpr1-HMpr7 influence
foreach v of varlist HMpr1-HMpr7 {
bysort influence: egen re_`v'=mean(`v')
}

keep influence re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(influence) j(HM_7)

ren influence lab
decode lab, g(re_lab)
g byvar="N of groups included in a model"

save "prpHM_influence.dta", replace
restore

* region
preserve
g byte temp =us
drop us
ren temp us

label define lb_us  0 "Not U.S." 1 "U.S."
label values us lb_us

keep HMpr1-HMpr7 us
foreach v of varlist HMpr1-HMpr7 {
bysort us: egen re_`v'=mean(`v')
}

keep us re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(us) j(HM_7)

ren us lab
decode lab, g(re_lab)
g byvar="Region"

save "prpHM_region.dta", replace
restore

* Partisanship
use "coef_wide.dta", clear
label define lb_us  0 "Not U.S." 1 "U.S."
label values us lb_us

meologit HM_7 global i.issue i.party influence distance_HM ln_n pre_diff_HM if us==1 & p_HL_10==1 || study:
predict HMpr* if e(sample)
keep if e(sample)

keep HMpr1-HMpr7 party
foreach v of varlist HMpr1-HMpr7 {
bysort party: egen re_`v'=mean(`v')
}

keep party re_*
duplicates drop re_HMpr1, force
reshape long re_HMpr, i(party) j(HM_7)

ren party lab
decode lab, g(re_lab)
g byvar="Partisanship"

save "prpHM_party.dta", replace


*** combining all estimates in one dataset
use "prpHM_issue.dta", clear
append using "prpHM_global.dta"
append using "prpHM_influence.dta"
append using "prpHM_region.dta"
append using "prpHM_party.dta"

g id=1 if byvar=="Region"
replace id=2 if byvar=="N of groups included in a model"
replace id=3 if byvar=="Partisanship"
replace id=4 if byvar=="General political ideology"
replace id=5 if byvar=="Issue"

label values lab .

save "prpHM_all.dta", replace

** Combing all high-low and high-middle comparisons
use "prpHM_all.dta", clear
append using "prpHL_all.dta"
g pr=re_pr
replace pr= re_HMpr if pr==. 
drop re_pr re_HMpr

g class="High vs low income" if HL_7!=.
replace class="High vs middle income" if HM_7!=.

replace HL_7=HM_7 if HL_7==.
replace HM_7=HL_7 if HM_7==.

save "pr_comb.dta", replace
